﻿using System;
using System.Runtime.InteropServices;

namespace CustomWindows.Window_API
{
    public class Transparency:WindowsFunction
    {
        /// <summary>
        /// Transparent appearance
        /// </summary>
        public enum WindowStyle
        {
            Extended = -20, // GWL_EXSTYLE - Sets a new extended window style.
            Alpha = 0x02,  // LWA_ALPHA - Use bAlpha to determine the opacity of the layered window
            Layered = 0x80000 // WS_EX_LAYERED - a new extended window style bit
        }

		#region Constructors (1) 

        public Transparency(IntPtr hwnd) : base(hwnd)
        {
            Description = "Transparency";
            EventLogger = new Event(DateTime.Now, Hwnd, Description);
        }

		#endregion Constructors 

		#region Methods (1) 

		// Public Methods (1) 

        public override void UpdateFunction()
        {
            SetWindowLong(Hwnd, (int)WindowStyle.Extended,
                          GetWindowLong(Hwnd, (int)WindowStyle.Extended) ^ (int)WindowStyle.Layered);
            SetLayeredWindowAttributes(Hwnd, 0, 128, (int)WindowStyle.Alpha);
        }

		#endregion Methods 

        #region API
        // Tranparent effect
        [DllImport("user32.dll")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll")]
        static extern int GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll")]
        private static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
        #endregion
    }
}
